local assets = {
	Asset("ANIM", "anim/musha_cristal.zip"),
	Asset("ATLAS", "images/inventoryimages/musha_cristal.xml"),
	Asset("IMAGE", "images/inventoryimages/musha_cristal.tex")
}

local function item_oneaten(inst, eater)
	if eater.components.musha_skills then
		eater:PushEvent("musha_gainexp", 15)
	end
end

local function ondeploy(inst, pt, deployer)
	local tree = SpawnPrefab("musha_appleplant")
	if tree ~= nil then
		tree.SetPlant(true)
		tree.Transform:SetPosition(pt:Get())
		inst.components.stackable:Get():Remove()
		if tree.components.pickable ~= nil then
			tree.components.pickable:OnTransplant()
		end
		if deployer ~= nil and deployer.SoundEmitter ~= nil then
			deployer.SoundEmitter:PlaySound("dontstarve/common/plant")
		end
	end
end

local function Enable_deploy(inst, isSpring)
	if isSpring then
		inst:AddComponent("deployable")
		--inst.components.deployable:SetDeployMode(DEPLOYMODE.ANYWHERE)
		inst.components.deployable.ondeploy = ondeploy
		inst.components.deployable:SetDeployMode(DEPLOYMODE.PLANT)
		inst.components.deployable:SetDeploySpacing(DEPLOYSPACING.MEDIUM)
	else
		inst:RemoveComponent("deployable")
	end
end

local function fn()
	local inst = CreateEntity()

	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddSoundEmitter()
	inst.entity:AddNetwork()

	inst.AnimState:SetBank("bulb")
	inst.AnimState:SetBuild("musha_cristal")
	inst.AnimState:PlayAnimation("idle")

	MakeInventoryPhysics(inst)
	MakeInventoryFloatable(inst, nil, nil)

	inst.entity:AddLight()
	inst.Light:SetFalloff(0.7)
	inst.Light:SetIntensity(.5)
	inst.Light:SetRadius(1.5)
	inst.Light:SetColour(69 / 255, 180 / 255, 200 / 255)
	inst.Light:Enable(true)
	inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")

	inst:AddComponent("edible")
	inst.components.edible.foodtype = FOODTYPE.VEGGIE
	inst.components.edible:SetOnEatenFn(
		function(inst, eater)
			SpawnPrefab("statue_transition_2").Transform:SetPosition(eater:GetPosition():Get())
		end
	)
	inst.components.edible.healthvalue = 30
	inst.components.edible.hungervalue = 5
	inst.components.edible.sanityvalue = 1000
	inst.components.edible:SetOnEatenFn(item_oneaten)

	inst:AddComponent("tradable")

	inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		return inst
	end

	Enable_deploy(inst, TheWorld.state.isspring)

	inst:WatchWorldState("isspring", Enable_deploy)

	inst:AddComponent("stackable")
	inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM

	inst:AddComponent("inspectable")

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/musha_cristal.xml"

	return inst
end

return Prefab("musha_cristal", fn, assets)
